package com.liefox.controller;

import com.liefox.pojo.Admins;
import com.liefox.pojo.Suffer;
import com.liefox.service.AdminService;
import com.liefox.service.SufferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
public class AdminsController {
    @Autowired
    private AdminService adminService;
    @RequestMapping(value = "/admin-sign-in",method = {RequestMethod.POST})
    public String adminSignin(Admins admins, String Email, Model model, HttpSession session){
        Admins adminsSignin = adminService.adminsSignin(admins);
        String adminsInfo = adminService.getAdminsInfo(Email);
        System.out.println(adminsInfo + "用户信息");
        String adminsName = adminService.getAdminsName(admins.getEmail(), admins.getPassword());
        if (adminsSignin != null) {
            /*用户信息*/
            session.setAttribute("SufferInfo", adminsInfo);
            /*登录拦截*/
            session.setAttribute("loginSuffer", adminsName);
            session.setAttribute("Email", Email);
            System.out.println(admins + "=》登录成功");
            return "/admin/adminIndex";
        } else {
            System.err.println(admins + "=》登录失败");
            model.addAttribute("msg", "邮箱地址或密码错误!");
            return "/admin/admin-sign-in";
        }
    }
}
